package org.xm.sk.vo.ob;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@ApiModel(value = "WxMsgTemplate", description = "微信公众号消息模板参数")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WxMsgTemplate {

    // 消息接收方
    String toUser;
    // 模板id
    String templateId;
    // 表单提交场景下，为 submit 事件带上的 formId；支付场景下，为本次支付的 prepay_id
    String formId;
    // 模板消息详情链接
    String url;
    // 消息顶部的颜色
    String topColor;
    // 参数列表
    List<WxMsgTemplateParam> templateParamList;
    
    public Map<String, Object> toMap() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("touser", this.getToUser());
        result.put("template_id", this.getTemplateId());
        result.put("form_id", this.getFormId());
        result.put("url", this.getUrl());
        result.put("topcolor", this.getTopColor());
        Map<String, Object> data = new HashMap<String, Object>();
        for (WxMsgTemplateParam wtp : this.getTemplateParamList()) {
            Map<String, Object> value = new HashMap<String, Object>();
            value.put("value", wtp.getValue());
            value.put("color", wtp.getColor());
            data.put(wtp.getName(), value);
        }
        result.put("data", data);
        return result;
    }

}
